rem auther:www.yumi-info.com
rem date:20171222
rem 要安装好压软件
rem ******MySQL backup start********
@echo off

set "_ZIP=C:\Program Files\2345Soft\HaoZip\HaoZipC.exe"

set mysqldump="D:\tool\mysql\mariadb-10.3.10-winx64\bin\mysqldump"

set "back_prefix=backup_"
set "backup_root_dir=.\"
set "Ymd=%date:~0,4%-%date:~5,2%-%date:~8,2%"

rem if "%time:~0,1%"==" " set "hour=0%time:~1,1%"

if "%time:~0,2%" lss "10" (set hour=0%time:~1,1%) else (set hour=%time:~0,2%)

echo "hour:"%hour%

set "Hms=%hour%%time:~3,2%%time:~6,2%"
set "YmdHms=%Ymd%%Hms%"
set db_host=127.0.0.1
set db_port=3306
set db_user=root
set db_pwd=123


set "backup_dir_name=%back_prefix%%YmdHms%"

set "backup_dir=%backup_root_dir%\%backup_dir_name%"

echo "backup_dir:"%backup_dir%

forfiles /p "%backup_root_dir%" /m %back_prefix%* -d -10 /c "cmd /c rd /s/q @path"

md %backup_dir%

set db_name=tio_sitex_conf
"%mysqldump%" --opt --single-transaction=TRUE --user=%db_user% --password=%db_pwd% --host=%db_host% --protocol=tcp --port=%db_port% --default-character-set=utf8 --single-transaction=TRUE --routines --events %db_name% > "%backup_dir%\%db_name%.sql"

set db_name=tio_sitex_main
"%mysqldump%" --opt --single-transaction=TRUE --user=%db_user% --password=%db_pwd% --host=%db_host% --protocol=tcp --port=%db_port% --default-character-set=utf8 --single-transaction=TRUE --routines --events %db_name% > "%backup_dir%\%db_name%.sql"



"%_ZIP%" a -tzip -p1015 "%backup_dir_name%.zip" "%backup_dir%\*"


@echo on
rem ******MySQL backup end********